<?php

$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
set_include_path(get_include_path().PATH_SEPARATOR.$baseDir.PATH_SEPARATOR.$baseDir.'/incubator');

include '../../testingfunctions.php';
include 'Pone/Pone_Exception.php';
include 'Pone/Database/Pone_Database_ConnectionFactory.php';
include_once './dbconfig.php'; // $config is defined here
include_once './test_setup.php'; // refreshTestData() is defined here

try
{
    refreshTestData($config);
    // /home/web/windows.php.net/docroot/downloads/snaps/
    $conn = Pone_Database_ConnectionFactory::getConnection($config);
    $stmt = $conn->createStatement();
    $rs   = $stmt->fetchRow('SELECT id, username FROM test2 WHERE id = 4');
    assertTrue(is_array($rs), 'Expected: Result set is an array. ');
    echo '<br />';
    assertTrue(isset($rs['id']) && isset($rs['username']), 'Expected: Result set array contains 2 fields named: id and username. ');
    echo '<br />';
    assertTrue(!(isset($rs[0]) && is_array($rs[0])), 'Expected: Result set array is not a two dimentional array. ');

    // Free resources
    $stmt->close();
}
catch (Pone_Exception_DatabaseAccess $ex)
{
    echo implode('. ', $ex->getTraceMessages());
    echo '<br />';
    echo $ex->getNativeMessage();
}
catch (Exception $ex)
{
    echo $ex->getMessage();
}

$conn->close();
?>